package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.CremationProvider;
import com.jinmdz.fmis.dao.model.cremation.CremationViewItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

/**
 * 火化Dao
 *
 * @author LiCongLu
 * @date 2020-02-15 19:33
 */
public interface CremationDao {

    /**
     * 按照主键获取火化信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-20 15:10
     */
    @SelectProvider(type = CremationProvider.class, method = "getCremationViewById")
    CremationViewItem getCremationViewById(@Param("id") Integer id);

    /**
     * 按照业务编码查询冷藏信息
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-16 16:28
     */
    @SelectProvider(type = CremationProvider.class, method = "listCremationViewByBusinessCode")
    ArrayList<CremationViewItem> listCremationViewByBusinessCode(@Param("businessCode") String businessCode);

    /**
     * 根据业务编码修改火化证号
     *
     * @param id             表ID
     * @param cremationNo    火化证号
     * @param modifiedUserId 修改人员
     * @param version        版本号
     * @return
     * @author GuanKui
     * @date 2020/2/19  17:07
     */
    @Update("update cremation  set  cremation_no = #{cremationNo} ,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) " +
            " where id = #{id} and version = #{version} and unmodified = 0 and deleted = 0")
    void updateCremationCertificateNoById(@Param("id") int id, @Param("cremationNo") String cremationNo, @Param("modifiedUserId") Integer modifiedUserId, @Param("version") Long version);

    /**
     * 判断火化证号是否存在
     *
     * @param cremationNo 火化证号
     * @return 火化证号
     * @author GuanKui
     * @date 2020/2/17 12:45
     */
    @Select(" select cremation_no " +
            " from cremation " +
            " where cremation_no = #{cremationNo} and deleted=0 and as_active=1 limit 1 ")
    String hasCremationNo(@Param("cremationNo") String cremationNo);

    /**
     * 按照业务编码获取激活状态的火化信息
     *
     * @param businessCode 业务编码
     * @return
     * @author GuanKui
     * @date 2020/2/21 14:59
     */
    @SelectProvider(type = CremationProvider.class, method = "getCremationViewAsActiveByBusinessCode")
    CremationViewItem getCremationViewAsActiveByBusinessCode(@Param("businessCode") String businessCode);


}
